﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;
using System.Reflection;

namespace RHFrameWork
{
    public class WebSiteProcess
    {
        List<PageProcess> lst = new List<PageProcess>();

        public WebSiteProcess(Assembly assem)
        {
            foreach (Type typ in assem.GetTypes())
            {
                if (typ.IsSubclassOf(typeof(PageProcess)) == true)
                {
                    lst.Add((PageProcess)assem.CreateInstance(typ.FullName));
                }
            }
        }

        public virtual ProcessResult Process(Uri url, HtmlDocument Doc,UserInfo user)
        {
            foreach (PageProcess pp in lst)
            {
                ProcessResult pr = pp.Process(url,Doc, user);
                ProcessResult.Out(pr);
                if (ResultProcess(pr) == true)
                {
                    return pr;
                }
            }

            return ProcessResult.Get(enumProcessResult.未处理, this);
        }

        private bool ResultProcess(ProcessResult pr)
        {
            switch (pr.ID)
            {
                case enumProcessResult.处理成功:
                    return true;
                case enumProcessResult.处理失败:
                    return true;
                default:
                    return false;
            }
        }
    }
}
